<template>
 <div>
  <home-header :city="city"></home-header>
  <home-swiper :swiperList="swiperList"></home-swiper>
  <home-icon :iconList="iconList"></home-icon>
  <home-recommend :recommendList="recommendList"></home-recommend>
  <home-weekend :weekendList="weekendList"></home-weekend>
 </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcon from './components/Icon'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axios from 'axios'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcon,
    HomeRecommend,
    HomeWeekend
  },
  data () {
    return {
      city: '',
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: []
    }
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json').then(this.setHomeInfo)
    },
    setHomeInfo (res) {
      res = res.data
      if (res.ret && res.data) {
        const dat = res.data
        this.city = dat.city
        this.swiperList = dat.swiperList
        this.iconList = dat.iconList
        this.recommendList = dat.recommendList
        this.weekendList = dat.weekendList
      }
    }
  },
  mounted () {
    this.getHomeInfo()
  }
}
</script>
